package com.klun.designMode.proxy.JDKProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 定义一个代理
 */
public class MyProxy implements InvocationHandler {
    private Person person;

    //获取被代理人的资料
    public Object getInstance(Person target) throws Exception {
        this.person = target;
        Class zz = target.getClass();
        return Proxy.newProxyInstance(zz.getClassLoader(), zz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是中介：您的性别是:男");
        System.out.println("开始海选");
        method.invoke(this.person,args);
        System.out.println("如何合适的话，就准备办事");
        return null;
    }
}
